포스트

02. 스프링 핵심 원리 이해

02. 스프링 핵심 원리 이해

스프링 핵심 원리 이해

spring.io 에 들어가서 초기 파일 가져오기

  • core.zip으로 만들어진걸 intellji로 import 하기

에러 발생

1
2
3
4
5
6
7
8
9
A problem occurred configuring root project 'core'. > 
Could not resolve all artifacts for configuration ':classpath'. >
 Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.2.4. 
 Required by: project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.2.4 > No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.2.4 was found. The consumer was configured to find a library for use during runtime, compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.7' but: 
 - Variant 'apiElements' declares a library, 
 packaged as a jar, and its dependencies declared externally: - Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 11 
 - Other compatible attribute: 
 - Doesn't say anything about org.gradle.plugin.api-version (required '8.7') - Variant 'javadocElements' declares a component for use during runtime, and its dependencies declared externally: - 
 Incompatible because this component declares documentation and the consumer needed a library - Other compatible attributes:
  • spring core는 Java 17이상부터 가능하다
  • Java 11 ⇒ Java 17로 변경해서 해결

회원 도메인 설계 및 개발

회원 도메인

클라이언트 - > 회원 서비스 - > 회원 저장소

  • 이것을 구현한다면?
  • 저장소는 별도로 재정의하지 않음
    • 그렇다면 임시적인 Repositroy를 클래스로 만들어 임시 저장소로 활용한 뒤 추후 교체 한다.

회원 도메인 개발

1
2
3
4
5
public class MemberServiceImpl implements MemberService{

	private final MemberRepository memberRepository = new MemberRepositoryImpl();
	
	...
  • 이 부분은 DIP을 위반한 사례
  • memberRepository가 MemberRepository 인터페이스를 의존하는 것은 옳다.
  • 하지만 service는 MemberRepository와 MemberRepositoryImpl 모두에게 의존된 형태
  • 이게 왜 잘못된 설계인 것인지는 추후 공부…

주문과 할인 도메인 설계

  • 주문과 할인 정책
    • 회원의 상품, 할인, VIP의 대한 대우, 어떤 할인 정책… 할지 모른다.

클라이언트 → 주문 서비스 → 회원 저장소 , 할인 정책역할 → 주문 서비스 → 클라이언

Untitled

  • 역할과 구현을 분리 → 자유롭게 구현 객체를 조립
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.

© 김규형. 일부 권리 보유

Powered by Jekyll with Chirpy theme